Clean up the logic a bit