major refactor to requirejs