Moving some code around so it's easier to change.