move filehandling code to utils module