modified hapcut.c