[Edited online] - Refactor type-of-file function.