not part of this PR, but this method needs comments on the top. Also, seems to have grown overly big