general cleanup

check whether file exists before doing a is_open() test;
general code cleanup