improve error handling mechanism