rewritten to support notifications