Added lots of parameter calculations & some refactoring.