refactored for iOS and Android