Fixes #3664, actually make sense of this function to work properly