Removed duplicate code around upcasting