merge some bug fixes from official source