Minor cleanup

- Fixed a bunch of notices
- a small efficiency tweak in a foreach
- visibility on class variables and functions
- auto-whitespace removal