Added client deregistering, little better error handling