now with some more error handling