Refactored combinations code