Fixed the flow of the code