fixed invariant calculation (only doing 'N' invariants at the moment)