Small library optimization
Add additional error check
Add unit library functions for statistical functions