some refactoring, code cleanup