More error checking, bug fixes, and support of X-Real-IP