ported changes from master HEAD to here