added Require.js, some improvements and refactoring