fixes #5 with code from @sprintstar