Used hni code with minor modifications