Fix first patch based on previous comments
Fix some crashes