fix seg fault and remove debug