Did some refactoring and documentation