some refactoring, loggin added