arranged write to abg correctly