Complete rewrite of FDR calculation