Refactor UserController from constructor to factory function