Fixes for Memory leaks, NPEs, races and optimizations

Change-Id: Iee07b13ba02d8aab9cc43567aa5df131cc43c737
Merge "Fixes for Memory leaks, NPEs, races and optimizations" into du44