some refactoring for clarity