Casting object properly