Bug Fixes [NOT TESTED]

- restructured loops
- implemented comments