Comment a lot and output both headers
Catch write errors
Solve a few bugs