added comments and minor changes