refactoring, move some functions to new modules