add test for functions and fix the problems with the scope int the functions