Code to handle file swapping