Fixed bug and added comments