added comments and minor enhancement.