re-factored core.js