refactored, simplified