Updated to handle case where $controller is an object