Refactored elisp code