Fix spacing and style issues
Refactor large method into smaller methods and replace 'and' and 'or'