center logic of the api for easier error handling