The code needs to be audited and solid principles applied. There is redundant code in typefinding. Extract type finding code perhaps even delete it.