#27: Some refactoring and speed-ups.