Fix for MB-11165, tests for MB-11165 and MB-11166