Exec refactoring

Remember to merge https://github.com/appium/appium/pull/4103 after this.
I guess readable in this case depends on the person.

This is another pattern that we could nicely consolidate into a helper function.