finish the function