build and sell function