Fixed a bug

Fixed a bug and added comments