Fixed casting of Objects to instance class