Instead of just casting I would try to use directly the right type. It should be doable, I can have a look this week-end if you want.