Adding unittests, lots of little bug fixes found in testing.  Small ammout of API changes