In place of failure create new window ID in case of duplicate ID

Fixes #545
Fixes #537