refactor check and cleanup