Fixes #9, slick trick from stackoverflow https://stackoverflow.com/a/14501015/692179