moving state variables into main function