Further refactoring

Added more detailed documentation.