some refactoring for readability