Replace calls to deprecated APIs, remove some unused imports.