added comments and fixed minor things