Add tests, code documentation, refactoring.

any suggestions?
a positive integer is better