refactor and clean up core.js