improve error handling in dispatch