Improved the listen code