quality function and some tests.