possible improvements
adapting code to author's suggested changes
Merge pull request #1 from tangrammer/master

thanks!