big generic refactor