Tentatively working version of efficient "CalcF" function.