Now ensures cleanup and deallocing resources before exit