First commit for version 2. Completely rewrote everything.
code cleanups.