Fix to_fits and add a test