I'm not sure this function is 100% correct. Can we get some tests for it?