restructure js and fix bug about Model