fixed adding headers before writing calling WriteHeader