Changed type check from Equals to IsAssignableFrom.