Moved api code to services