refactored. much less terrible.