Minor refactor: use closed flag rather than valid