Cleanup, rearrange, add comments.