added some structure to the code