some refactoring here