modified version and fixed a wonky string read