done part of buy.js