MAINT: removing loops for vectorisation.  Fixing some problems in equations<->calculation code.