Removing this and adding window as a global variable