Some lua cleaning and a crash fix