Add multi attachment support. Small code refactoring