code cleanup and in-code documentation