Refactors the loadbalancer
Refactors the loadbalancer, adds tests for it