refactor, little cleanup. still ify but maybe more maintainable