Refactored some methods for filename handling.