Wrapped all header() calls with "if ( ! headers_sent())" conditional to prevent "Headers already sent" error.