Code cleanup (see desc)

- Redundancies removed
- Null checks
- Decreased nesting
- More consistent naming