modified quit in case of resource leak