make scoping dynamic to fix #967