Turns out I also had a bug in isInstanceOf. It was too simple and couldn't catch all possible cases.