How to avoid wiping out your equity gains