Did some refactoring and cleanup