further cleanup

moved the isopen() check to a function