improve API and error handling