Code cleanup, error proofing

- cleaned up code, removed obsolete functions and variables
- NPE-proofing in several places
- fixed validation of event termination tags
- improved lowercase detection
- corrected non-uppercase <type> not being  registered as an error