finished some refactoring