Added functionality to extract attachments.
Added better error reporting and handling.