refactored!!!