Cleanup, small fixes and more and better tests