cleaning and better filetype checking