Cleaned up window mode code.