PSR code cleanup

A handful of refactoring and formatting changes:

- [x] Private and protected functions and variables SHOULD NOT contain a leading single underscore.
- [x] Opening braces MUST go on the next line for functions and methods. Also removed spaces after last function and method calls.
- [x] Remove leading whitespace after class opening.
- [x] Clean up comments.