Make modules order-independent

Set up modules so that they may be split across files and loading order
does not matter. Fix up various syntax and jshint errors.