Added tracking of a rotated basis

Added a smarter basis tracking routine and discovered a few errors in
the fitting code: Mind the p's and q's.

DSB