Implemented sharding logic + test.

Oleg, 
I created a separate brunch and committed there sharding logic implementation+ test. Please review.