Pull request #34 by @henriquelampert.

This is the code from pull request #34 with very little refactory.