defer after checking err