refactored code to use dispose method rather thanh manual unloading