Fixed a bug with quality calculation for multi-level output