Fixed API binding and added error handling