how does investing in stocks work