added some explanatory text and a tiny bit of error handling