code cleanup, attachments fix, maybe something more