Cleaned up the code and added some minor style stuff.