refactoring core.js