Moved some functions to main