Cleaned some code, added a lot more comments