Fix cant set headers after they are sent error