remove calls to deprecated APIs and remove some unchecked casts