Partially merge from Android branch