consolidated some api code