refactoring in pre.js