fix bugs and prepare for read input file