Moved functions out of main.cpp