Fixing formatting and restructuring code to be more clear.