SOme refinements to the codes to make this branch and the master branch match more closely