cleanup code and add basic api support (wip)