merged some useful fixes from android branch