This is the kind of function that would need some unit tests IMHO