count 5xx response and clean up code
licensed to ASF