Finally fixed the implementation, the values returned are in fact valid and the order of the given strings is not a factor.