Don't call set_window too often
Close file after reading
Test