Fix some typings and casting.