Clean up file handling in main.c a bit