Add a couple more casts so that code compiles correctly.