big assed refactor