Fix filename substring issue