bugfix scope fix
add test function and fix bug