refactored code for reddit