added strict error checking and target application
check if there's an open document