Reconciliation cost function & tests

Should be pretty much ok to use in cactus; waiting for memory leak
check.