Moved functions to header files, separated main