Some reordering of file generation so that we can do fewer redundant checks