const-correctness and some minor performance improvements.