refactor buy