Performance optimization. Fixes #3.
Refactoring.