Made all into AMD modules and major refactor into separate modules.