refactor client processing erlang style