bulk of gem code