Fix casting issues