code refactor, was getting unwieldly thick