upgraded with changes from several other repositories