added more structure to code