Minor cleanups and performance improvments