improve read function