Add some casts to fix warnings; patch from Greg Wright