Fixed several functions to make integration much (~10x ?) faster.