This should be extracted into a function.