Reimplemented the spirit of pull request #9