Added some file name edge cases and refactored filename handling