Synchronized fixes

There are 2 issues which impact the shark performance significantly. The fix will not help in Hive, but will improves the performance by x10 in Shark in some circumstances.