improve error trap