fixing multiple client handling and errors in code