Fixed attachment threading problem.
Formatted the code.