added more detailed comments and got rid of some extraneous code