implement badly performing combinations function