Add error handling to stack script