fix #646 define scope of variables