Improved connection scan algorithm and implemented a waiting window