Revised and applied Yue's patches

Change-Id: I863c5ea05c23cb9e1f739c3b303513788484b1a6