Most of this is just reorganization to make the match between the C file and python written files better.