encapsulated code
some refactoring