attempting without global variables