Fixed bugs, and add read from file