Refactored so the common code between -ref and -pthread is in noelkdf-common.c