fix json interface and improve error handling