Reorganize lib to use requirejs