some cleanup and crash fix