Move file-sorting code outside the view functions
Misc style changes
Match file extensions case-insensitively

I truly didn't realise this wasn't already done until someone sent me a .BMP file.