add API, modularize model code