Fixes #9 and improves performance.