Cleaned up formatting and indentation.
Lots of standardization and changes to exception handling and checks for null arguments / invalid operations.