Implement an offline mode and other refactoring