Optimize removing unused fields code