Refactor attach event a bit