fixing crash - dynamic cast