Slightly more useful / general example
Fix + improve error checking