refactored the code, added read smaple