Continued refactoring of logic.js.