refactor overlay window code