code updated for iPhone and iPad