file handling and basic validation