Refactoring and better documentation. Minor visual changes.