Fix generating ring-related bugs