initial import of code and some supporting bits