run optional handler function when finished