add unit test + minor fixes