Fixed return_code typo
Fixed case, closed sockets, and missing return issues