Improved cuevent code