Refactor file handler out of main file