fixed bug and added comments