fix misplaced logic