ported several changes from 1.3