Fixed wrong statistics after service close and fixed export for API lower than 19 (try-with-resources not supported).