Improved client and added some safeguards