fixed issue where cache wasn't being deleted, and attempted to add more
safeguards to make process more reliable.