Moved this to a function for testability sake with 59cff9d784fc3aa801ff18d221e5aefd8167a211