Add patch client/server function and reorganize things