Added auto detecting require.js source url + code refactoring