Moved out main functions to separate files