simplified solution
Merge pull request #567 from abhinavc/master

Simpler solution