Did some refactoring