Version 3. Several bug fixes.
Removing debug code