Fixed the code to work correctly on Android