Changing the controller so it can be reused in the frontend too