Remove function from loop for apply lib to controller