implement robuster version of setDocumentListener() + add test for it