Refactored and generalized candidate calculation