Refactored evaluate() method.