added tests for small values, tweaked algo
snapshot