Fixed a bug and added comments