Added tests and fixed broken tests.
Bug fixes.