Bug fix class scope inside function