Optimized the notifications code