moved stuff, added comments, cleaned up code