Restructured and simplified code -- not yet final

Have restructured the code and simplified readability.

Primary functionality is working ok.

However fails for the following:
cr <- corr("specdata", 5000)
summary(cr)

returns:
Mode    NA's
logical       0

instead of expected:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
##