refactored to functions and added file arg