rearrange, add some more checks