Fairly large performance improvement. Fixes #9