move notification code from frontend to model