attachment handling, error handling, logging, cleanup