fixed attachment timeout issue; code tidy