replace some repetitive code with @eval generation