Update the code with function