Fixed Connection answer header
Use isset() instead of is_resource() here and there
Some small optimizations