Unit-tests and small fixes