Improved constructor logic for files