Fixed a bug, and did some cleanup