Re-formatted most of the code to comply to PSR-2
Refactored if statements to make it more readable and comply to PSR-2