refactor principal tracking, handle missing configuration better, add unit tests