Add missing check for valid window