Fix longest non-overlapping repeating substring method to work correctly on all inputs.