how does stock investing work