refactoring: split the code