Fix a bug and added comments