modified the reader logic for better integration in Java