Added comments and cleared up some of the code