cleanup and add metrics