Removed redundant checks in while loops thanks to checking for a valid index at beginning of methods
Added comments