Extract shared code to neighborly-balanced

This is the code that is being extracted to `neighborly-balanced` gem.