FileTypeImpl: refactoring and fix some leaks