re-revert accidentally reverted changes

Sometimes cherry-picking code isn't a bad idea. ;-)
This should fix all the changes that have been reverted by the followed merged pull request.
Merge pull request #118 from darealshinji/patch-1

re-revert accidentally reverted changes