rewrite to accelerate emacs