Changed lerp function to be more generic.