compute cost works for multiple vars