Fixed a few issues related to attachment management