refactored the script.

The script works now fine using selendroid-standalone.