Updated function calculateR