some basic changes: moving all api logic to model; optimizing interconnection