crash fixed and some cleanup