Refactored save_ghost routine.