implemented polymorphic cast

cleanup is necessary