refactored. made worse