Add analytics code and fix a couple small issues