Remove some duplicate code from client