integrated some changes from cyandream

Change-Id: I2e9c044659d334777bc071538c8f6ae2efe00088