Revised pull request and fixed other bugs.