Works for low values of CLIENT_NUMBER; cleaned up code