added comments and cleaned it up