move some functions at the right place