Fix scope of cast