change some logic. This fixes #14 and #9