fix bug that would only return error responses for 3rdparty apps
logout before output to not run into header already sent problems
respect format output