Stable calculations for unstable particles: restoring gauge invariance