Fixing a bug where two extensions were applied to filename

A huge thanks to @brockboland for his work on this.