Code cleanup and doc improvements