Fixed bugs and made work in requirejs