Code review feedback

Rearrange function a bit.