refactored based on suggestions