refactored into states