Cleanup  - moving utility code out of api