reworked logic