code cleanup

check whether file exists before doing a is_open() test;
general code cleanup
Merge pull request #1 from thisisnian/master

Thanks.