some refactoring and prettifying