bugfix + optimization

Optimized and fixed bugs (tested)
Merge pull request #1021 from banggugyangu/4.1-dev

bugfix + optimization