Refactor client sync code, more client tests