Fix enormous bug caused by multiple windows

closes #37