fixed bug and added comments
fixed bug and added comments