attach.js: refactoring