move delta calc to function