fixes #98 and simplifies code.