Clean up and simplify some logic