added assert and debug + corrected double free error