Reworked logic a little bit