Close the connection immediately after registering statistics
Add missing headers