CORE-2002: added unit tests and fixes