This is the first big refactoring step towards v1.0 Lots of functions changed places and names, so there are probably lots of bugs to correct now.