DRY few code and ensure tmp folder delete