fixed #4: modify to calc fileindex correctly