refactor check logic