Moved functions from main.cpp to external files