Fix an ordering problem where we have changed the order in which functions are now called. This turns out to also make the code much simpler :-)