Cleaned up irrelevant code, added more comments