Remove unreachable code and fix logic error
Clean up dm2 attachment loading and attachment url usage a little