added comments and cleaned it a little