Refactor and add test for notification