xe: Improve errorhandling and cleanups