Added a function to determine the quality. It is preliminary.