Units tests, code cleanup, etc