better logic and better comments.