separate functions from main.cpp