Re-apply pull request #6 from ajishbabu/master