a bit more error handling