Improve notification handling logic