Fixed segmantation issue

Actually using original code