finished up the function