Code commenting and miscellaneous cleaning

Added commenting to most of the code as well as a number of todos where
applicable. Cleaned up the JS a bit and the PHP app modules.