Check which import statements are actually needed and trim them if not.