Finished some refactoring