The changes to this function need unit testing