fix reader and make more maintainable