gets res-to-ref working dynamically