Controller.js refactored to pass tests