added read func. fixed some bugs.