refactor some functions into main app