I found the problem.
fixed the seg fault, function not working properly