Fix to handle errors in defer_stack