Fix null pointer on error bug