Add further unit tests, minor code improvements