fixed the seg fault error