finished api and some logical issues to correct