Fixed bugs in client handle cleanup.
Fixed return in case of invalid handle.