updated controller function