some fixes to improve error handling