Sharding implementation, refactoring src/test and util