GATEWAY-3351: code updated and unit tests fixed.