Added dir flag. Removed old func used for caching.