Add support for custom remote-ip header. Move user-related code. Add stats endpoint (incomplete).