fixed some redundant code and replaced it with getFileExtension