Improve logic a bit