complicated refactor I will regret