optimize implementation
Merge pull request #334 from jiang42/master

optimize implementation