Implementing nbh function