read function now works properly