Moved this to it's own function so it can be tested in case of changes