improved text r/w logic