Refactor inference engine