make tmp code more readable
fix tmp file handling
Merge pull request #86 from rkitover/tmp

fix some issues with tmp files