Broke up main math kernel into its 3 component calculations. Fixed some
index errors.