Refactored the fitsheader script and improved its tests.