Complete various problems, change file input procedure