Add inferFunc; small refactorings