improve qec function for emacs