several bugfixes, all events now modify current state correctly, including indices. Attach and detach were problems, attach must also create a new window, and detach must check if old window needs to be deleted. Some events weren't firing because of missing properties crashing the script.