Moved things around, fixed bugs, and added more comments