Added rectangle selection logic