Implemented document methods for operating with attachments.
Basic tests.
Several minor bugfixes.