refactored more than I can remember