Move helper function to scope level so that it can be easily changed