code cleanup and error handling for notifications