Restructure select/cons_res to move some data from stack to heap