Code cleanup

- Replaced hardcoded magic numbers with defines.
- Removed pyramid ifs
- Add a few spaces after commas.