Readding class cast fix to this branch.