lots of clean-ups, unit test improvements