fix casting errors