fixes #297, could use a proper rewrite
Merge pull request #304 from iBotPeaches/master

fixes #297