Initial Edit

Edited the flow of the code