reorganized proto_lib.c