Fix global variable and formatting issues. Add some todos, and fix a few bugs on iOS.