Bug fix from melan (https://gist.github.com/melan/5205776)