adding offline mode, refactoring code