fix problem with name collisions with temp file, just use a counter instead