Refactored for clarity and better out of stock handling