Factoring out different parts
Removing reference to tmp_file