logic refactor