Fixes for SHARK-176, SHARK-173

applied the fix for non-deterministic output from 0.9 branch to 0.11