BS-9684: rename package from attachment to document
Clean code, remove dead code which revealed a possible infinite loop