add scope guard statements
fix bug with functions test