Fixing attachment code