Refactor away instanceof checks