Updated iOS code from Matt