VE-1520 refactor to move the clean up code to a separate method