Fixes the non-removal of overlay on error.