edit to use instanceof, not try