Merge bug fixes from 1.2.x branch