How do capital gains work?