Fix nullpointer in API, fix #693