fixed issue with class loading and destruction due to scope loosing