refactor to ddd
Cursed is the devil spawn of Javascript, and Cursed is it's closures. Cursed is its weird scoping rules, and cursed is it's vagueness. It's poor debugging facility is also cursed. Fixed it so we don't have repeating code.