Use better casts

Change-Id: Ibcf2d715ac306bd4bedae716ad82c614f136d1bc