bugs fixes and crash handling