From original rBc0bd240ad0a1 commit, issues reported with suggested fixes by Wayde Moss (@GuiltyGhost), thx.