Fixed counting errors and loop mistake
minor bug and comments resolved
Merge https://github.com/RagingRanek/statistical-methods
Fix ordering of vectors in extract. Equalize with python version.