refactoring cose