changed all upcast conversions to downcast