Moved functions to be called from a singular main function