Fix some bugs in first version by debugging on local machine.