more sensible error handling all round