working code with reconfigurable window