added comments, minor bug fix