Code cleanup

General code cleanup (removed commented out code, minor refactoring of
methods, added additional state enforcement/checks).