added patches from RobertCNelson