VID-1976 adding more unit tests and slightly refactoring code