Fix compilation and seg fault issues