Fixed issue with can't set headers after they are sent