Simplify and clean up some logic