Did some refactoring to improve quality