Random refactoring of lib/core.js