Refactor in the logic