Fix a hint insertion/replacement bug and add unit tests to guard against its return.