Switch logic order so it doesn't fail when there's an error