fixes #98 and does some much-needed cleanup