-Have a look at this code that adds in error checking, let me know if you have any questions; 

![image](https://f.cloud.github.com/assets/3854347/2328389/c1571b36-a3fd-11e3-89d0-d24ee294637b.png)