Added logging and corrected closure errors.
Added some more unit tests.