Cleaning up some logic