Code cleanup and doc cleanup