Call on_assignment and perform rebalance when using js

Includes a nice refactor. Fixes #171