Code Organisation

Grouping code blocks and removing extra spaces.
Repeated code blocks arranged.