Refactored code with new Reader class instead of nested class for readability.