Refactored Android code to match iOS version