Refactor significantly to be better performant.