fixed a bug and addded comments