Refactor Logic