More documentation, some refactoring and other tweaks.