Refactoring the nbif code