Refactor sell function (in progress)