Better error handling; updated comments; updated example