Refactored bad name
Moved the conditions around to be more understandable
Refactored the finding of the filename outside the method for opening