Fixed code when error occurs