Cleaned up and added a few more comments