working version of rayleight fit.