Modified new index/tmp file handling to prevent fd leak
removed some sneaky whitespace