Updated code so it works on file protocol as well.