Fixed some bugs.
Merged with master.