Fixed crashes with incorrect api usage