pull request

Fixed a few issues, although there still are some bugs there. It tested on more than 5500 lines of source code.