Fixed attach event function