Algorithm should work but I am getting Index out of bounds errors