finish function.