Added unittests + small cleanups