Code cleanups and doc improvements