Code from Ray Wenderlich tutorial.  Extended with my modifications.