Surely uniqueness_look_back can be 0? (In general I hate the idea of to_i == 0 as a way of detecting whether a string represents an integer)