Fixed some bugs from the automatic reformatting of the code. Also, minor code cleanup.