Error handling to avoid loosing the script