Refactor file handling code to FileController