Fixed formatting exceptions, added some documentation, and cleaned the code up a bit.