Cleaned up duplicated code in the header attaching