some refactoring, commenting