A lot of this logic is the same as in `define_method. What can we do about this?