rebuilt as an api, need more fixes