back ported changes from oldpatricka develop PR