Fix errors when setting headers