adapted code to work on Android