Refactored iOS specific functionality to be cleaner and more flexible