Fix reference issues hidden by cast