Fix type casts

This not bug fixes. Just surpress warnings and improve type consistencies.