finished the wavecal algorithm