Moved functionality out of main.cpp