Applied slightly modified version of lluis' Pull Request.

Closes PR#47.