Fixed a type error and nil protected socket cleanup.