Removed commented reference code, added more comments, fixed minor outOfBounds related bug