Fixed tons of bugs and optimize the scripts.