Fix nasty type casting issue