Better handling of the error per @jamesls' feedback.