This is probably a better way to get around those isinstance calls.