More refactoring and comments.
Removed some dead code.