FastDiag is implemented, some refactoring is performed