code cleanup and docs