change function order so that if y depends on x, y comes after x