Fixed some bugs and clean code.