avail: move more code from client.c