Move logic to where (I think) it belongs