Fix bug in finding file extension