Rearranged abrest's code