Rtefcst - first part of xray re-alignment

This branch is a merge between your most recent master (9dcc88a) and wpfcst / the old pull request (791830e). The immediate merge conflicts are resolved but the re-alignment with xary will take some more work. Not ready to be merged yet; I opened the PR so we can discuss some of the changes that also affect your previous code and move this branch forward. 

I added some line comments on 3f33a45 (parent of latest commit) since that one still has the diff to the original code from your master.  The last commit (d58d136) is simply a deletion of temporary comments and commented-out code.

Just would like to check before I start messing more with your code...