Refactored for offline usage.