fix unopened file case
best approach yet
cleanup for code review