improved the solution (e65dd85) to the seg fault issue