Various cleanups.
* Added and cleaned up comments.
* Added checks to prevent map server crashes.
* Cleaned up some reports from CPPCheck.
* Other various stylization cleanups.