Attempt to refactor logic