Improvements to buy.sell function