refactored basket code