incorporated changes from latest PR