Refactoring apm.el