refactored for smoother flow