Extract the remaining bottles calculation to a separate function