Refactored and returning data structure instead of streaming for better processing