code cleanup and extra documentation