cleaned up code in client and listener.