code refactor.
Split separate function to modules