Added edge case handling
Minor adjustments

Some file handling additions and changes