Move logic into controllers, fix and add new client side unit tests