refactored code:method accepts the filename as an argument