Major refactoring

Now works when headers are already present