These implementations of get_next_key() obviously don't match each other. Please add documentation for what the function is supposed to do and explain why one of them is different.